/**
 * Created by Administrator on 2018/7/18.
 */
$CertusJsonAjax.ajax("queryBusinessQuotation",{
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
},function(res){
    $$scope.processCCBXTrace = res.data;
})
var tempRejectStepInstanceId;
$CertusJsonAjax.ajax('businessQuotationBaseInfo', {
    "processInstanceId": $CertusJsonAjax.getProInstanceId(),
    "stepInstanceId": $CertusJsonAjax.getStepInstanceId()
}, function (res) {
    $$scope.proj = res.data.proj;
    res.data.business.id = '';
    $$scope.business = res.data.business;
    tempRejectStepInstanceId = $$scope.business.stepInstanceId
    $$scope.business.proInstanceId = $CertusJsonAjax.getProInstanceId();
    $$scope.business.stepInstanceId = $CertusJsonAjax.getStepInstanceId();

    dataInit = $CertusJsonAjax.dataInit("quoteItemList", {bqCode: $$scope.business.bqCode}, quoteItemPronum, 'priceContainer', 'priceToolBarContainer');
    $$scope.getProjLv = function (projLv) {
        if (projLv == "1") {
            return "低";
        } else if (projLv == "2") {
            return "中";
        } else if (projLv == "3") {
            return "高"
        }
    }

    $$scope.attachmentDownBusiness = function () {
        $CertusFormAjax.download("attachmentDownBusiness", "uploadFilePath=" + $$scope.business.uploadFilePath);
    }

    //不通过
    $$scope.denied = function () {
        $$scope.business.originReason = "denied";
        $CertusJsonAjax.ajax("endBusinessQuote",$$scope.business,function(res){
            if(res.data.succed == "success"){
                window.history.back();
            }
        })
    }

    $$scope.veto = function () {
        $$scope.business.originReason = "veto";
        $$scope.business.rejectedInstanceIds = tempRejectStepInstanceId
        $CertusJsonAjax.ajax("vetoBusinessQuote",$$scope.business,function(res){
            if(res.data.succed == "success"){
                window.history.back();
            }
        })
    }

    $$scope.promise = function () {
        $$scope.business.originReason = "promise";
        $CertusJsonAjax.ajax("endBusinessQuote",$$scope.business,function(res){
            if(res.data.succed == "success"){
                window.history.back();
            }
        })
    }
})


var quoteItemPronum = [{
    id: 'category',
    title: '分类',
    width: 160,
    type: 'string',
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        return getQuoteItem(value);
    }
}, {
    id: 'cataPrice',
    title: '目录价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'discountedRate',
    title: '折扣率',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = value + '%';
        return content;
    }
}, {
    id: 'discountPrice',
    title: '折后价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'taxRate',
    title: '税率',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = value + '%';
        return content;
    }
}, {
    id: 'taxPrice',
    title: '含税价',
    type: 'string',
    width: 100,
    columnClass: 'text-center',
    resolution: function (value, record, column, grid, dataNo, columnNo) {
        var content = '￥' + value + '元';
        return content;
      }
}, {
    id: 'descriptor',
    title: '说明',
    type: 'string',
    columnClass: 'text-left',
}];


function getQuoteItem(id) {
    if (id == "1") {
        return "软件";
    } else if (id == "2") {
        return "软件license";
    } else if (id == "3") {
        return "硬件";
    } else if (id == "4") {
        return "服务";
    } else if (id == "5") {
        return "软件定制";
    } else if (id == "6") {
        return "一次性折扣";
    }
}